import 'package:flutter/material.dart';
import 'package:flutter_bilibili/cache/hi_cache.dart';
import 'package:get/get.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      theme: ThemeData(
        useMaterial3: false, // 禁用Material3样式
        primarySwatch: Colors.blue,
      ),
      home: const ContentPage(),
    );
  }
}

class ContentPage extends StatefulWidget {
  const ContentPage({super.key});

  @override
  State<ContentPage> createState() => _ContentPageState();
}

class _ContentPageState extends State<ContentPage> {
  final TextEditingController _textEditingController1 = TextEditingController();
  final TextEditingController _textEditingController2 = TextEditingController();
  late String content = '';

  @override
  void dispose() {
    _textEditingController1.dispose();
    _textEditingController2.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('测试缓存')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text(
              'key：',
              style: TextStyle(fontSize: 30),
            ),
            Padding(
              padding: const EdgeInsets.only(left: 20, right: 20),
              child: TextField(
                controller: _textEditingController1,
              ),
            ),
            const Text(
              'value：',
              style: TextStyle(fontSize: 30),
            ),
            Padding(
              padding: const EdgeInsets.only(left: 20, right: 20),
              child: TextField(
                controller: _textEditingController2,
              ),
            ),
            ElevatedButton(
              onPressed: () async {
                HiCache().setString(
                    _textEditingController1.text, _textEditingController2.text);
              },
              child: const Text('添加缓存'),
            ),
            Container(
              height: 40,
              width: MediaQuery.of(context).size.width,
              margin: const EdgeInsets.only(left: 20, right: 20),
              decoration: const BoxDecoration(
                color: Colors.green,
              ),
              child: Padding(
                padding: const EdgeInsets.only(left: 20),
                child: Text(content),
              ),
            ),
            ElevatedButton(
              onPressed: () async {
                setState(() {
                  content =
                      HiCache().get(_textEditingController1.text).toString();
                });
              },
              child: const Text('获取缓存'),
            )
          ],
        ),
      ),
    );
  }
}
